package com.my.page;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.my.framework.web.mvc.controller.BaseController;

import lombok.extern.slf4j.Slf4j;

@RequestMapping
public class LoginController extends BaseController {

	private String appName;
	private Menu menu;

	public LoginController(String appName,Menu menu) {
		this.appName=appName;
		this.menu=menu;
	}

	@RequestMapping("/getToken")
	@ResponseBody
	public Map<String, String> getToken(HttpServletResponse response, String userName, String passwd,
			Integer remeberMe) {
		Map<String, String> map = new HashMap<>();
		map.put("message", "success");
		log.info(userName + "登录成功");
		return map;
	}

	@RequestMapping("/logout")
	public String logout(HttpServletResponse response) {
		return "login";
	}

	@RequestMapping({"/","/index"})
	public ModelAndView index() {
		ModelAndView view = new ModelAndView();
		view.setViewName("index");
		view.addObject("menuList", menu.getChildren());
		view.addObject("appName", appName);
		return view;
	}

}
